"""MxShop URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.urls import path, include

from django.views.generic import TemplateView
from rest_framework.routers import DefaultRouter
from rest_framework.authtoken import views
from rest_framework.documentation import include_docs_urls

# 这是早期第三方jwt
from rest_framework_jwt.views import obtain_jwt_token

import xadmin

from rest_framework.schemas import get_schema_view
from rest_framework_swagger.renderers import SwaggerUIRenderer, OpenAPIRenderer
schema_view = get_schema_view(title='DRF学习项目', renderer_classes=[OpenAPIRenderer, SwaggerUIRenderer])

from goods.views import GoodsListViewSet, CategoryViewSet, GoodsDetailViewset
from users.views import SmsCodeViewset, RegisterViewset, UserInfoAPIView, UserInfoModifyAPIView
from score.views import StudentView
from trade.views import ShoppingCartAPIView, ShoppingCartModifyAPIView, ShoppingCartDeleteAPIView, OrderCreateAPIView, OrderListAPIView, OrderDetailAPIView
from user_operation.views import UserFavAPIView, LeavingMessageAPIView, UserAddressViewSet


# 配置路由
router = DefaultRouter()
# 商品列表路由
router.register('goods/list', GoodsListViewSet, basename="goods_list")
# 商品详情路由
router.register('goods/detail', GoodsDetailViewset, basename="goods_detail")
# 商品分类路由
router.register('category', CategoryViewSet, basename="category")
# 短信验证码路由
router.register('code', SmsCodeViewset, basename="code")
# 用户注册的路由
router.register('register', RegisterViewset, basename="register")
# 用户收货地址路由
router.register('address', UserAddressViewSet, basename="address")


urlpatterns = [
    # DRF 文档
    path('doc/', include_docs_urls(title="DRF学习项目")),
    # 后台管理系统
    path('xadmin/', xadmin.site.urls),
    # 配置路由
    path('', include(router.urls)),
    path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
    # 获取token
    path('api-token-auth/', views.obtain_auth_token),
    # jwt
    path('login/', obtain_jwt_token),
    # 用户收藏
    path('user_fav', UserFavAPIView.as_view(), name="user_fav"),
    path('user_fav/<goods_id>', UserFavAPIView.as_view(), name="user_fav"),
    # 用户信息
    path('user_info', UserInfoAPIView.as_view(), name="user_info"),
    path('user_info_modify', UserInfoModifyAPIView.as_view(), name="user_info"),
    # 用户留言
    path('leaving_message', LeavingMessageAPIView.as_view(), name="leaving_message"),
    # 购物车
    path('shopping_cart', ShoppingCartAPIView.as_view(), name="shopping_cart"),
    path('shopping_cart_modify/<goods_id>', ShoppingCartModifyAPIView.as_view(), name="shopping_cart_modify"),
    path('shopping_cart_delete/<goods_id>', ShoppingCartDeleteAPIView.as_view(), name="shopping_cart_delete"),
    # 订单相关
    path('order_create', OrderCreateAPIView.as_view(), name="order_create"),
    path('order_list', OrderListAPIView.as_view(), name="order_list"),
    path('order_detail/<pk>', OrderDetailAPIView.as_view(), name="order_detail"),
    # 自学的模块
    path('students/', StudentView.as_view(), name="students"),
    # swagger接口文档路由
    path('swagger/', schema_view, name="docs"),
]
